# 朴素贝叶斯
from sklearn.naive_bayes import MultinomialNB
# 决策树
from sklearn.tree import DecisionTreeClassifier
# 支持向量机
from sklearn.svm import SVC
# 神经网络
from sklearn.neural_network import MLPClassifier
# 集成学习：装袋法 与 随机森林
from sklearn.ensemble import BaggingClassifier
from sklearn.ensemble import RandomForestClassifier
# 分类报告
from sklearn.metrics import classification_report


# 朴素贝叶斯
def nb(X_train_tfidf, X_test_tfidf, y_train, y_test):
	mnb = MultinomialNB()						# 初始化
	mnb.fit(X_train_tfidf,y_train)				# 建立模型
	y_predict = mnb.predict(X_test_tfidf)		# 参数预测

	c_report = classification_report(y_test, y_predict)
	print('\n[$] 朴素贝叶斯|分类报告\n\n', c_report, '\n')


# 决策树
def dt(X_train_tfidf, X_test_tfidf, y_train, y_test):
	tree = DecisionTreeClassifier(criterion="gini")			# 初始化
	tree = tree.fit(X_train_tfidf, y_train)					# 建立模型
	y_predict = tree.predict(X_test_tfidf)					# 参数预测

	c_report = classification_report(y_test, y_predict)
	print('\n[$] 决策树|分类报告\n\n', c_report, '\n')


# 支持向量机
def svm(X_train_tfidf, X_test_tfidf, y_train, y_test):
	svm = SVC(kernel='linear')					# 初始化
	svm.fit(X_train_tfidf, y_train)				# 建立模型
	y_predict = svm.predict(X_test_tfidf)		# 参数预测

	c_report = classification_report(y_test, y_predict)
	print('\n[$] 支持向量机|分类报告\n\n', c_report, '\n')


# 神经网络
def mlp(X_train_tfidf, X_test_tfidf, y_train, y_test):
	mlp = MLPClassifier(solver='lbfgs', alpha=1e-5, hidden_layer_sizes=(4,4), random_state=1)	# 初始化
	mlp.fit(X_train_tfidf, y_train)																# 建立模型
	y_predict = mlp.predict(X_test_tfidf)														# 参数预测

	c_report = classification_report(y_test, y_predict)
	print('\n[$] 神经网络|分类报告\n\n', c_report, '\n')


# 集成学习
# 装袋法
def bg(X_train_tfidf, X_test_tfidf, y_train, y_test):
	bg = BaggingClassifier()					# 初始化
	bg.fit(X_train_tfidf, y_train)				# 建立模型
	y_predict = bg.predict(X_test_tfidf)		# 参数预测

	c_report = classification_report(y_test, y_predict)
	print('\n[$] 集成学习-装袋法|分类报告\n\n', c_report, '\n')

# 随机森林
def rf(X_train_tfidf, X_test_tfidf, y_train, y_test):
	rf = RandomForestClassifier(n_estimators=300, max_depth=150, n_jobs=1)		# 初始化
	rf.fit(X_train_tfidf, y_train)												# 建立模型
	y_predict = rf.predict(X_test_tfidf)										# 参数预测

	c_report = classification_report(y_test, y_predict)
	print('\n[$] 集成学习-随机森林|分类报告\n\n', c_report, '\n')

